<template>
  <div class="content-container">
    
    <!-- 工具栏 -->
    <div ref="adminContentTools" class="content-tools-wrap hidden">
      	<div class="tools-left f-l">
      		
      		<el-button-group>
             <el-button type="primary" @click="handleAdd">新增</el-button>
			   </el-button-group>

      	</div>
      	<div class="tools-right f-r">
      		
			      <div class="search-wrap" style="display: inline-block;">
              <el-input placeholder="请输入关键词" v-model="query.keywords">
                <template slot="append">
                  <i class="icon el-icon-search"></i>
                </template>
              </el-input>
            </div>
			
      	</div>
    </div>
    <!-- 内容栏--表格 -->
    <div class="content-table-wrap" v-loading="loading" loading-type="chrome-circle-turn" :style="{height:ResultHeight+'px'}">

    	<el-table
	        border
	        v-if="data"
	        size="small"
	        :data="data"
	        :height.sync="tableHeight"
	        :header-cell-style="{background:'#42b983',color:'#ffffff'}"
	        :cell-style="{borderWidth:0}"
	        style="width: 100%"
      	>
    		
	        <el-table-column
	          	fixed
	          	prop="id"
	          	label="ID"
	          	width="120">
	        </el-table-column>

    		<el-table-column
		      	prop="orderNo"
		      	label="制令单号"
		      	width="150">
		    </el-table-column>

		    <el-table-column
          		prop="finishTime"
          		label="完工时间"
          		width="150">
        	</el-table-column>

		    <el-table-column
		      	prop="productName"
		      	label="产品名称"
		      	width="150">
		    </el-table-column>

		    <el-table-column
		      	prop="warehouseName"
		      	label="仓库名称"
		      	width="150">
		    </el-table-column>

        	<el-table-column
          		prop="finishNum"
          		label="完工数量"
          		width="80">
        	</el-table-column>

        	<el-table-column
          		prop="batchNo"
          		label="批号"
          		width="80">
        	</el-table-column>

	        <el-table-column
	          	prop="payHash"
	          	label="缴库Hash"
	          	width="150">
	        </el-table-column>

	        <el-table-column
	          	prop="hashTime"
	          	label="Hash时间"
	          	width="150">
	        </el-table-column>

	        <el-table-column
	          	prop="blockHash"
	          	label="区块Hash"
	          	width="150">
	        </el-table-column>


			<el-table-column
	          	class="oprate"
			    fixed="right"
			    label="操作"
	          	width="180"
			>

		      	<template slot-scope="scope">
            
	            	<i class="icon iconfont ipc-clear" @click="handleDel(scope.row)"></i>
	            	<i class="icon iconfont ipc-edit" @click="handleEdit(scope.row)"></i>
	            	<i class="icon iconfont ipc-search-online"></i>

		      	</template>

		    </el-table-column>

    	</el-table> 

      	<!-- 分页 -->
      	<div ref="adminContentPagination" class="content-pagination-wrap">
	        <el-pagination
	            background
	            :current-page="page.currentPage"
	            :page-sizes="pageSizes"
	            :page-size="page.pageSize"
	            layout="total, sizes, prev, pager, next, jumper"
	            :total="page.total"
	            @current-change="currentPageChange"
	        >
	        </el-pagination>
      	</div> 
    </div>

    <!-- 修改dialog -->
    <edit-dialog
    	:visible="editDialogVisible"
    	:form.sync='editForm'
      	:type="editType"
    	@cancel="editDialogCancel"
      	@confirm="editDialogConfirm"
    ></edit-dialog>

  </div>

</template>

<script>
import { mapGetters } from 'vuex';

import {
  list,
  edit,
  del,
} from "@/api/track/manufact-process";

import editDialog from '@/components/agriculture/track/manufact-process-edit-dialog.vue'; 

import adminMixins from "@/mixins/admin";

export default {
  name: 'role',
  mixins:[adminMixins],
  components:{
  	editDialog,
  },
  computed: {
    ...mapGetters([
      'name',
      'permission',
      'userInfo'
    ])
  },
  data(){
  	return{
      query:{
        keywords:''
      },
      //1新增，2修改
      editType:1,
      loading:true,
  		//修改模态框的显示隐藏
  		editDialogVisible:false,
  		data:null,
      testData:[
        {
          id:"334995096",
          number:"73F15233E6F3",
          online:'在线',
          name:"山东师范农场采集设备2",
          acquisitionTime:"2019-12-19 16:34:49",
          data:'18 ℃ | 36.4 %RH | 3767.9 ℃ | 16.3 %RH ',
        }
      ],
  		page: {
    	  pageSize: 10,
    	  currentPage: 1,
    	  total: 0
  	  },
  	  pageSizes:[10,20,30,40,50,100],
  	  editForm:null
  	}
  },
  mounted(){
    //设置dom尺寸
    this.setSize();
  	this.loadData(this.page)
  },
  methods:{
  	//请求table数据
  	loadData(page, params = {}){
  		  this.loading = true;
      	list(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {

        	this.loading = false;
          const result = res.data.data.records;
          
          console.log("-------------3333333-------------")
          console.log(res)
          this.page.currentPage = res.data.data.current;
          this.page.total = res.data.data.total;
        	this.data = this.convertData(result);

          //this.data = this.testData;
      	});
      	
  	},
    convertData(data){

      return data;
    },

    //新增
    handleAdd(){
        this.editForm = {};
        this.editType = 1;
        //模态框显示
        this.editDialogVisible = true;
    },
    //刷新当前页
    refresh(){
      this.loadData(this.page)
    },
  	//点击操作的编辑
  	handleEdit(row){
  		this.editType = 2;
      this.editForm = row;
      //模态框显示
      this.editDialogVisible = true;
      
  	},
  	//点击操作的删除
  	handleDel(row){
  		console.log(row)

  		this.$confirm('此操作将永久删除该信息, 是否继续?', '提示', {
          	confirmButtonText: '确定',
          	cancelButtonText: '取消',
          	type: 'warning'
        }).then(()=>{
        	return del(row.id);
        }).then((res) => {

        	this.loadData(this.page)
          	this.$message({
            	type: 'success',
            	message: '删除成功!'
          	});
        }).catch(() => {
          	this.$message({
            	type: 'info',
            	message: '已取消删除'
          	});          
        });
  	},
  	//取消
  	editDialogCancel(){
  		this.editDialogVisible = false;
  		this.editForm = null;
  	},
    //确认
    editDialogConfirm(form){
      this.editDialogVisible = false;

      edit(form.data).then((res)=>{

        //this.editDialogVisible = false;
        this.loadData(this.page)
            this.$message({
              type: 'success',
              message: '添加成功!'
            });
      })

      
    },
    //页面改变
    currentPageChange(val){
      this.page.currentPage = val;
      //请求数据
      this.loadData(this.page);
    },
    getDeviceData(data){
      var arr = [];
      if(data.airHumidity){
        arr.push(data.airHumidity) 
      }
      if(data.airTemperature){
        arr.push(data.airTemperature) 
      }
      if(data.soilConductivity){
        arr.push(data.soilConductivity) 
      }
      if(data.soilMoisture){
        arr.push(data.soilMoisture) 
      }

      if(data.soilTemperature){
        arr.push(data.soilTemperature) 
      }

      if(arr.length){
        return arr.join('|')
      }
      return '';
    }
  }
}
</script>

<style lang="scss" scoped>
.content {
  &-container {

  }
  /***搜索栏***/
  &-search-wrap{
    padding: 15px;
    border-bottom: 1px solid #E8EBEE;
  }
  /***工具栏***/
  &-tools-wrap{
    padding: 15px;
  }
  /***内容栏***/
  &-table-wrap{
    position: relative;
    padding: 15px;
    .cell{
      .icon{
        margin-right: 10px;
      }
    }
  }
  /***分页***/
  &-pagination-wrap{
    text-align: right;
  	padding-top: 15px;
  }
}
</style>
